package com.ruoyi.web.demoController;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.web.domain.DemoTest;
import com.ruoyi.web.domain.dto.ArticleRequestDTO;
import com.ruoyi.web.service.IDemoTestService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * demo测试Controller
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Api(tags="demo测试管理")
@RestController
@RequestMapping("/demo/test")
public class DemoTestController extends BaseController
{
    @Autowired
    private IDemoTestService demoTestService;

    /**
     * 查询demo测试列表
     */
    @ApiOperation("查询demo测试列表")
    @PreAuthorize("@ss.hasPermi('demo:test:list')")
    @GetMapping("/list")
    public TableDataInfo list(DemoTest demoTest)
    {
        startPage();
        List<DemoTest> list = demoTestService.selectDemoTestList(demoTest);
        return getDataTable(list);
    }

    /**
     * 导出demo测试列表
     */
    @ApiOperation("导出demo测试列表")
    @PreAuthorize("@ss.hasPermi('demo:test:export')")
    @Log(title = "demo测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoTest demoTest)
    {
        List<DemoTest> list = demoTestService.selectDemoTestList(demoTest);
        ExcelUtil<DemoTest> util = new ExcelUtil<DemoTest>(DemoTest.class);
        util.exportExcel(response, list, "demo测试数据");
    }

    /**
     * 获取demo测试详细信息
     */
    @ApiOperation("获取demo测试详细信息")
    @PreAuthorize("@ss.hasPermi('demo:test:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(demoTestService.selectDemoTestById(id));
    }

    /**
     * 新增demo测试
     */
    @ApiOperation("新增demo测试")
    @PreAuthorize("@ss.hasPermi('demo:test:add')")
    @Log(title = "demo测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoTest demoTest)
    {
        return toAjax(demoTestService.save(demoTest));
    }

    /**
     * 修改demo测试
     */
    @ApiOperation("修改demo测试")
    @PreAuthorize("@ss.hasPermi('demo:test:edit')")
    @Log(title = "demo测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoTest demoTest)
    {
        return toAjax(demoTestService.updateById(demoTest));
    }

    /**
     * 删除demo测试
     */
    @ApiOperation("删除demo测试")
    @PreAuthorize("@ss.hasPermi('demo:test:remove')")
    @Log(title = "demo测试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(demoTestService.removeByIds(Arrays.asList(ids)));
    }


    /**
     * 策略模式-根据不同文章类型进行不同处理测试
     */
    @ApiOperation("策略模式-根据不同文章类型进行不同处理测试")
    @PostMapping("/publishAnArticle")
    public AjaxResult publishAnArticle(@RequestBody @Valid ArticleRequestDTO dto)
    {
        return demoTestService.publishAnArticle(dto);
    }

    /**
     * 策略模式-根据不同符号进行不同计算方式
     */
    @ApiOperation("策略模式-根据不同符号进行不同计算方式")
    @PostMapping("/countStrategy")
    public AjaxResult countStrategy(@RequestBody @Valid ArticleRequestDTO dto)
    {
        return demoTestService.countStrategy(dto);
    }


}
